package com.zhl.jvm.chapter2;

import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;

/**
 * @program: demos
 * @description:
 * @author: 刘振华
 * @create: 2020-07-07 11:47
 **/
public class TestMain {
//	public static String getAttachType(String majorcategory, String minorcategory, String attachcategory, String attachDicttypeCode) {
//		String attachType = majorcategory + "/" + minorcategory + "/" + attachcategory + "/" + attachDicttypeCode;
//		return Hex.encodeHexString(attachType.getBytes());
//	}
	public static String getMajorcategory(String attachType) {
		return getCategorys(attachType)[0];
	}

	public static String getMinorcategory(String attachType) {
		return getCategorys(attachType)[1];
	}

	public static String getAttachcategory(String attachType) {
		return getCategorys(attachType)[2];
	}

	public static String getAttachDicttypeCode(String attachType) {
		return getCategorys(attachType)[3];
	}

	public static String[] getCategorys(String attachType) {
		return (new String(hexDecode(attachType))).split("/");
	}
	public static byte[] hexDecode(String input) {
		try {
			return Hex.decodeHex(input.toCharArray());
		} catch (DecoderException var2) {
			throw new IllegalStateException("Hex Decoder exception", var2);
		}
	}

	public static void main(String[] args) {
		String[] strs = getCategorys("d1b9c1a6b9dcb5c02fcfd6b3a1d5d5c6ac2fcfd6b3a1d5d5c6ac2f");
		for(String tmp:strs){
			System.out.println(tmp);
		}
	}
}
